import request from '@/utils/request'

const workFlowPrefix = '/workflow'

// const uumsPrefix = '/uums'

// 获取流程分类树形结构
export function wfBizCategoryTree(args) {
  return request({
    url: workFlowPrefix + '/WfBizCategory/treeSelect?',
    method: 'POST',
    data: args
  })
}

// 查询流程分类
export function wfBizCategorySelect(args) {
  return request({
    url: workFlowPrefix + '/WfBizCategory/select',
    method: 'POST',
    data: args
  })
}

// 插入流程分类
export function wfBizCategoryInsert(args) {
  return request({
    url: workFlowPrefix + '/WfBizCategory',
    method: 'POST',
    data: args
  })
}

// 更新流程分类（通过主键ID）
export function wfBizCategoryUpdateById(args) {
  return request({
    url: workFlowPrefix + '/WfBizCategory/' + args.bizCateId,
    method: 'PUT',
    data: args
  })
}

// 删除流程分类（通过主键ID）
export function wfBizCategoryDelete(args) {
  return request({
    url: workFlowPrefix + '/WfBizCategory/force',
    method: 'DELETE',
    data: args
  })
}

// 获取流程
export function wfProcessSelect(args) {
  return request({
    url: workFlowPrefix + '/WfProcess/queryProcess?',
    method: 'POST',
    data: args
  })
}

// 获取流程（通过流程分类）
export function wfProcessSelectByCateId(args) {
  return request({
    url: workFlowPrefix + '/WfProcess/queryProcessByCateId?bizCateId=' + args.bizCateId,
    method: 'POST',
    data: args
  })
}

// 流程删除
export function wfProcessDelete(args) {
  return request({
    url: workFlowPrefix + '/WfProcess/deleteWfProcess?',
    method: 'DELETE',
    data: args
  })
}

// 流程激活
export function wfProcessActive(args) {
  return request({
    url: workFlowPrefix + '/WfProcess/active?processId=' + args.procId + '&processVersion=' + args.procVersion,
    method: 'POST',
    data: args
  })
}

// 流程复制
export function wfProcessCopy(args) {
  return request({
    url: workFlowPrefix + '/WfProcess/copyProcess?processId=' + args.procId + '&processVersion=' + args.procVersion + '&bizCateId=' + args.bizCateId,
    method: 'POST',
    data: args
  })
}

// 流程分类更改
export function wfProcessChangeCategory(args) {
  return request({
    url: workFlowPrefix + '/WfProcess/updateProcessCategory?processId=' + args.procId + '&bizCateId=' + args.bizCateId,
    method: 'POST',
    data: args
  })
}

// 流程导出
export function wfProcessExport(args) {
  const baseApi = process.env.BASE_API + workFlowPrefix
  let downloadSourcePath = baseApi + '/WfProcess/doExportProcess?processId=' + args.procId + '&processVersion=' + args.procVersion
  let downloadElement = document.createElement('a')
  downloadElement.target = '_blank'
  downloadElement.href = downloadSourcePath// 此处可以通过拼接字符串的方式传递参数
  document.body.appendChild(downloadElement)
  downloadElement.click() // 点击下载
  document.body.removeChild(downloadElement) // 下载完成之后移除元素
}

